﻿@model WebEntities.Models.WebInfo.News

@{
    ViewBag.Title = "网站管理平台_编辑新闻";
}

@section HeadContent
{
    <script type="text/javascript">
        var getNewsContent = function () {
            var content = App.Description.getValue();
            if (App.NewsContent.iframe != null) {
                content = App.NewsContent.iframe.dom.contentWindow.getContent();
            }
            App.Description.setValue(content);
        }
    </script>
}

@(Html.X().Viewport()
    .Layout("fit")
    .Items(
        Html.X().TabPanel().Items(
            Html.X().FormPanel()
                .ID("FormPanel1")
                .Layout("Column")
                .Title("头信息")
                .Items(
                    Html.X().Panel()
                        .Border(false)
                        .ColumnWidth(0.5)
                        .Layout("form")
                        .Defaults(
                            Html.X().Parameter().Name("AnchorHorizontal").Value("90%")
                        )
                        .Items(
                            Html.X().HiddenFor(m => m.NewsID).ID("NewsID"),
                            Html.X().HiddenFor(m => m.Description).ID("Description"),
                            Html.X().TextFieldFor(m => m.NewsTitle).ID("NewsTitle").FieldLabel("新闻标题").AllowBlank(false).MaxLength(50),
                            Html.X().ComboBoxFor(m => m.NewsType).ID("NewsType").FieldLabel("新闻类别").Editable(false)
                                .Store(Html.X().Store()
                                    .Model(Html.X().Model().IDProperty("TypeID")
                                        .Fields(
                                            new ModelField("TypeID", ModelFieldType.Int),
                                            new ModelField("TypeName")
                                        )
                                    )
                                    .Proxy(Html.X().AjaxProxy().Url(Url.Action("GetAllNewsType", "NewsType")).Reader(Html.X().JsonReader().Root("data")))
                                )
                                .DisplayField("TypeName")
                                .ValueField("TypeID"),
                            Html.X().ComboBoxFor(m => m.CataID).ID("CataID").FieldLabel("所属新闻目录").Editable(false)
                                .Store(Html.X().Store()
                                    .Model(Html.X().Model().IDProperty("CataID")
                                        .Fields(
                                            new ModelField("CataID", ModelFieldType.Int),
                                            new ModelField("CataName")
                                        )
                                    )
                                    .Proxy(Html.X().AjaxProxy().Url(Url.Action("GetAllNewsCata", "NewsCata")).Reader(Html.X().JsonReader().Root("data")))
                                )
                                .DisplayField("CataName")
                                .ValueField("CataID"),
                            Html.X().TextFieldFor(m => m.Publisher).ID("Publisher").FieldLabel("作者").MaxLength(50),
                            Html.X().ComboBoxFor(m => m.NewsStatus).ID("NewsStatus").FieldLabel("搜索文章").Editable(false)
                                .Items(
                                    Html.X().ListItem().Text("显示").Value("1").Mode(ParameterMode.Raw),
                                    Html.X().ListItem().Text("隐藏").Value("2").Mode(ParameterMode.Raw)
                                ),
                            Html.X().HiddenFor(m => m.NewsCover).ID("NewCover"),
                            Html.X().FileUploadField().ID("NewsCoverFile").FieldLabel("上传封面").Icon(Icon.ImageAdd).ButtonText("").Text(Model.NewsCover),
                            Html.X().TextFieldFor(m => m.NewsSrc).ID("NewsSrc").FieldLabel("文章来源").MaxLength(40)
                        ),
                    Html.X().Panel()
                        .Border(false)
                        .ColumnWidth(0.5)
                        .Padding(5)
                        .Layout("form")
                        .Defaults(
                            Html.X().Parameter().Name("AnchorHorizontal").Value("90%")
                        )
                        .Items(
                            Html.X().TextFieldFor(m => m.SubTitle).ID("SubTitle").FieldLabel("副标题").MaxLength(50),
                            Html.X().TextFieldFor(m => m.Keywords).ID("Keywords").FieldLabel("关键字").MaxLength(50),
                            Html.X().DateFieldFor(m => m.PubTime).ID("PubTime").FieldLabel("发布时间"),
                            Html.X().NumberFieldFor(m => m.SortNum).ID("SortNum").FieldLabel("排序序号").MinValue(0),
                            Html.X().ComboBoxFor(m => m.Important).ID("Important").FieldLabel("重要性").Editable(false)
                                .Items(
                                    Html.X().ListItem().Text("一般").Value("1").Mode(ParameterMode.Raw),
                                    Html.X().ListItem().Text("重要").Value("2").Mode(ParameterMode.Raw)
                                ),
                            Html.X().TextFieldFor(m => m.FileTitle).ID("FileTitle").FieldLabel("附件名称").MaxLength(50),
                            Html.X().HiddenFor(m => m.NewsFile).ID("NewFile"),
                            Html.X().FileUploadField().ID("NewsFileUpload").FieldLabel("上传附件").Icon(Icon.ImageAdd).ButtonText("").Text(Model.NewsFile)
                        )
                )
                .TopBar(
                    Html.X().Toolbar().Items(
                        Html.X().Button().Text("保存").Icon(Icon.Disk)
                            .DirectEvents(de =>
                            {
                                de.Click.Action = "EditNews";
                                de.Click.EventMask.ShowMask = true;
                                de.Click.EventMask.Msg = "正在保存";
                                de.Click.Success = "ext.net.comjs.onSubmitSuccess";
                                de.Click.Failure = "ext.net.comjs.onSubmitFailure";
                                de.Click.IsUpload = true;
                            })
                            .Listeners(ls =>
                            {
                                ls.Click.Handler = "getNewsContent(); return ext.net.comjs.onFormSubmit()";
                            })
                    )
                )
                .BottomBar(Html.X().StatusBar().DefaultText("Ready"))
                        .Listeners(ls => ls.ValidityChange.Handler = "ext.net.comjs.setFormStatusBar(this, valid)"),
            Html.X().Panel().ID("NewsContent").Title("新闻内容").Loader(
                Html.X().ComponentLoader()
                    .Url(Url.Action("NewsDescription"))
                    .Params(p =>
                    {
                        p.Add(new Parameter("newsId", Model.NewsID.ToString()));
                    })
                    .Mode(LoadMode.Frame)
                    .LoadMask(lm =>
                    {
                        lm.ShowMask = true;
                        lm.Msg = "加载中，请稍候...";
                    })
            )
        )
    )
)
